package com.ruoyi.fjtseac.service

import com.ruoyi.common.constant.HttpStatus
import com.ruoyi.fjtseac.service.impl.PhotoServiceImpl
import com.ruoyi.fjtseac.util.Constants
import com.ruoyi.fjtseac.util.FileUtil
import org.springframework.web.multipart.MultipartFile
import spock.lang.Specification
import spock.lang.Unroll

/**
 *
 * @author jxl
 * @date 2022/8/17
 */
class PhotoServiceTest extends Specification{
    def fileUtil = Mock(FileUtil)
    def photoServiceImp = new PhotoServiceImpl(fileUtil)

    @Unroll
    def "uploadPhoto(multipartFile:#multipartFile, uuid:#uuid), code:#httpStatus"() {
        given:"添加参数"
        fileUtil.upload(photoFile, Constants.IMAGE, _ as String) >> photoUrl

        when:
        def response = photoServiceImp.uploadPhoto(photoFile, _ as String);

        then:
        with(response) {
            code == httpStatus;
            msg == resultMsg
        }

        where:
        photoUrl | photoFile || httpStatus | resultMsg
        "http://cos.guangdong.cn/photo" | null || HttpStatus.SUCCESS | "图片上传成功"
    }
}
